<#escape x as x?html>
    <#macro renderJournalFamily jf origin>
    <div id="journal_family_${jf.id}">
        <h2>${jf.name}</h2>

        <p>${jf.description!}</p>

        <#list jf.journals as journal>
        <@renderJournal journal origin/>
        </#list>

        <form class="journal_family_${jf.id}_add_journal hidden" action="/${origin!"home"}/add-journal" method="POST">
            <input type="text" name="name" value="The name of your new Journal"/>
            <input type="text" name="description" value="a brief description"/>
            <input type="submit" value="Submit"/>
            <button class="cancel" type="button">Cancel</button>
            <button class="add_journal add shown" type="button">Start new Journal</button>
            <input type="hidden" name="journalFamilyId" value="${jf.id}"/>
        </form>
        <a class="delete_journal_family" href="/delete-journal-family?id=${jf.id}">
            <button type="button">Delete this journal family</button>
        </a>
    </div>
    </#macro>

    <#macro renderJournal journal origin>
    <div id="journal_${journal.id}">
        <h3><a href="/journal?id=${journal.id}">${journal.name}</a></h3>
        <p>${journal.description!}</p>
        <ol>
            <#list journal.textEntries as entry>
                <li>
                <@renderTextEntry entry origin/>
                </li>
            </#list>
        </ol>

        <form class="journal_${journal.id}_add_entry hidden" action="/${origin!"home"}/add-entry" method="POST">
            <span>New Entry:</span>
            <textarea rows="5" cols="50" name="content"></textarea>
            <input type="hidden" name="journalId" value="${journal.id}"/>
            <input type="submit" value="Submit"/>
            <button class="cancel" type="button">Cancel</button>
            <button class="add_entry add shown" type="button">Add new entry</button>
        </form>

        <ol>
            <#list journal.timeserieses as timeseries>
                <li>
                <@renderTimeseriesLink timeseries/>
                </li>
            </#list>
        </ol>

        <form class="journal_${journal.id}_add_timeseries hidden" action="/${origin!"home"}/add-timeseries"
              method="POST">
            <span>New Timeseries:</span>
            <input type="text" name="name"/>
            <input type="text" name="description" value="a brief description"/>
            <input type="hidden" name="journalId" value="${journal.id}"/>
            <input type="submit" value="Submit"/>
            <button class="cancel" type="button">Cancel</button>
            <button class="add_timeseries add shown" type="button">Add new timeseries</button>
        </form>

        <a class="delete_journal" href="/${origin!"home"}/delete-journal?id=${journal.id}">
            <button type="button">Delete this journal</button>
        </a>
    </#macro>

    <#macro renderTimeseriesLink timeseries>
        <div id="timeseries_${timeseries.id}">
            <a href="/timeseries?id=${timeseries.id}">"${timeseries.name}</a>
            <a class="delete_timeseries" href="/${origin!"home"}/delete-timeseries?id=${timeseries.id}">
                <img src="/images/delete.png" name="delete timeseries"/></a>
        </div>
    </#macro>

    <#macro renderTextEntry entry origin>
        <div id="text_entry_${entry.id}">
            <span>${entry.time?datetime}: <#noescape>${entry.text}</#noescape></span>
            <a class="delete_text_entry" href="/${origin!"home"}/delete-text-entry?id=${entry.id}"><img
                    src="/images/delete.png" name="delete entry"/></a>
        </div>
    </#macro>

    <#macro renderCreateJournalFamilyForm>
        <form class="create_journal_family_form hidden" action="/create-journal-family" method="POST">
            <input type="text" name="name" value="The name of your new Journal Family"/>
            <input type="text" name="description" value="a brief description"/>
            <input type="submit" value="Submit"/>
            <button class="cancel" type="button">Cancel</button>
            <button class="create_journal_family add shown" type="button">Create new Journal Family</button>
        </form>
    </#macro>

    <#macro renderUser user>
        <table>
            <tr>
                <th>username</th>
                <td>${user.username}</td>
            </tr>
            <tr>
                <th>email</th>
                <td>${user.email}</td>
            </tr>
            <tr>
                <th>enabled</th>
                <td>${user.enabled?string}</td>
            </tr>
            <tr>
                <th>UUID</th>
                <td>${user.uuid}</td>
            </tr>
        </table>
    </#macro>

    <#macro renderJournalFamilies journalFamilies origin>
        <#list journalFamilies as jf>
        <@render.renderJournalFamily jf origin/>
        </#list>
    </#macro>
</#escape>